(*
 *  This file is part of SwfLib
 *  Copyright (c)2004 Nicolas Cannasse
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)

type float16 = int
type unknown = string
type action_count = int

(*
    JHMTASC java mapped types.
    jhmtasc_type is an abstract type used for new_mobj primitive
*)

type jobj = int
type jdynarray = int
type jhashtable = int
type string_list = jdynarray


(*type function_decl = int*)
type function_decl = {
	f_name : string;
	f_args : string list;
	mutable f_codelen : action_count;
}

type func2_flags =
	| ThisRegister
	| ThisNoVar
	| ArgumentsRegister
	| ArgumentsNoVar
	| SuperRegister
	| SuperNoVar
	| RootRegister
	| ParentRegister
	| GlobalRegister

type function_decl2 = {
	f2_name : string;
	f2_flags : func2_flags list;
	f2_args : (int * string) list;
	mutable f2_nregs : int;
	mutable f2_codelen : action_count;
}

type try_style =
	| TryRegister of int
	| TryVariable of string

type try_block = {
	tr_style : try_style;
	mutable tr_trylen : action_count;
	mutable tr_catchlen : action_count option;
	mutable tr_finallylen : action_count option
}

(*
type function_decl2 = int
type f2_flagsList = jdynarray
type f2_argsList = (int * string) list
type try_style = int
type try_block = int
*)

type push_item =
	| PString of string
	| PFloat of int32
	| PNull
	| PUndefined
	| PReg of int
	| PBool of bool
	| PDouble of float
	| PInt of int32
	| PStack of int
	| PStack2 of int
(*
type push_items = jdynarray
type push_item = int
*)

type actions = jdynarray
type action = int
type action_type =
	| AEnd
	| ANextFrame
	| APrevFrame
	| APlay
	| AStop
	| AToggleHighQuality
	| AStopSounds
	| AAddNum
	| ASubtract
	| AMultiply
	| ADivide
	| ACompareNum
	| AEqualNum
	| ALogicalAnd
	| ALogicalOr
	| ANot
	| AStringEqual
	| AStringLength
	| ASubString
	| APop
	| AToInt
	| AEval
	| ASet
	| ATellTarget
	| AStringAdd
	| AGetProperty
	| ASetProperty
	| ADuplicateMC
	| ARemoveMC
	| ATrace
	| AStartDrag
	| AStopDrag
	| AThrow
	| ACast
	| AImplements
	| AFSCommand2
	| ARandom
	| AMBStringLength
	| AOrd
	| AChr
	| AGetTimer
	| AMBStringSub
	| AMBOrd
	| AMBChr
	| ADeleteObj
	| ADelete
	| ALocalAssign
	| ACall
	| AReturn
	| AMod
	| ANew
	| ALocalVar
	| AInitArray
	| AObject
	| ATypeOf
	| ATargetPath
	| AEnum
	| AAdd
	| ACompare
	| AEqual
	| AToNumber
	| AToString
	| ADup
	| ASwap
	| AObjGet
	| AObjSet
	| AIncrement
	| ADecrement
	| AObjCall
	| ANewMethod
	| AInstanceOf
	| AEnum2
	| AAnd
	| AOr
	| AXor
	| AShl
	| AShr
	| AAsr
	| APhysEqual
	| AGreater
	| AStringGreater
	| AExtends
	| AGotoFrame of int
	| AGetURL of string * string
	| ASetReg of int
	| AStringPool of string list
	| AWaitForFrame of int * int
	| ASetTarget of string
	| AGotoLabel of string
	| AWaitForFrame2 of int
	| AFunction2 of function_decl2
	| ATry of try_block
	| AWith of int
	| APush of push_item list
	| AJump of action_count
	| AGetURL2 of int
	| AFunction of function_decl
	| ACondJump of action_count
	| ACallFrame (* no data *)
	| AGotoFrame2 of bool * int option
	| AUnknown of int * unknown

type clip = int
type tag = int
type do_init_action = int
type exports = jdynarray
type export = int

type tag_data =
	| TShowFrame
	| TDoAction of actions
	| TClip of clip
	| TDoInitAction of do_init_action
	| TExports of exports

type jlocal_ctx = int
type jsuper_bindings_obj = int
type jtags_obj = int
type to_remove = int

type 'a jhmtasc_type =
(* Basic Types *)
    |	JInt of int
    |   JIntOption of int option
    |   JBool of bool
    |   JObj of jobj
    |   JVoid
    |   JString of string
    |	JStringList of string_list
    |   JNup of 'a jhmtasc_type * 'a jhmtasc_type
    |	JArray of 'a jhmtasc_type list
    |   JDynArray of jdynarray
    |   JHashTable of jhashtable
    |   JSuperBindingsObj of jsuper_bindings_obj
    |   JLocalCtx of jlocal_ctx
    |   JTagsObj of to_remove
    |   JTagObj of to_remove
    |   JTagData of tag_data
    |   JExport of export
    |   JAction of action
    |   JActions of actions
    |   JActionType of action_type
(* __ APush Action *)
    |   JPushItem of to_remove
    |   JPushItems of to_remove
    |   JPushItemType of to_remove
(* __ AFunction2 Action *)
    |   JFunc2Decl of to_remove
    (*|   JFuncDecl of function_decl*)
    |   JFuncDecl of to_remove
    |   JFlagsList of to_remove
    |   JArgsList of to_remove
    |   JFunc2Flag of to_remove
(* __ ATry Action *)
    |   JTry of to_remove
    |   JTryStyle of to_remove
    |   JTryStyleType of to_remove

exception Error of string
let error msg = raise (Error msg)